﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using User.API.Data;

namespace User.API.Mapping
{
    public class AppUserMap
        : IEntityTypeConfiguration<AppUser>
    {
        public void Configure(EntityTypeBuilder<AppUser> builder)
        {
            //Table.
            builder.ToTable("AppUser");

            //Key.
            builder.HasKey("Id");

            //Property.
            builder.Property(t => t.Id)
                .HasColumnName("Id")
                .IsRequired();
            builder.Property(t => t.Name)
                .HasColumnName("Name")
                .HasMaxLength(36)
                .IsUnicode(true);
            builder.Property(t => t.Phone)
               .HasColumnName("Phone")
               .HasMaxLength(36)
               .IsUnicode(true);
            builder.Property(t => t.Tel)
               .HasColumnName("Tel")
               .HasMaxLength(36)
               .IsUnicode(true);
            builder.Property(t => t.Phone)
               .HasColumnName("Phone")
               .HasMaxLength(36)
               .IsUnicode(true)
               .IsRequired();
            builder.Property(t => t.Address)
               .HasColumnName("Address")
               .HasMaxLength(36)
               .IsUnicode(true);
            builder.Property(t => t.CardName)
              .HasColumnName("CardName")
              .HasMaxLength(36)
              .IsUnicode(true);
            builder.Property(t => t.Company)
              .HasColumnName("Company")
              .HasMaxLength(36)
              .IsUnicode(true);
            builder.Property(t => t.ProvinceId)
              .HasColumnName("ProvinceId");
            builder.Property(t => t.Province)
              .HasColumnName("Province")
              .HasMaxLength(36)
              .IsUnicode(true);
            builder.Property(t => t.CityId)
              .HasColumnName("CityId");
            builder.Property(t => t.City)
              .HasColumnName("City")
              .HasMaxLength(36)
              .IsUnicode(true);
            builder.Property(t => t.Avatar)
             .HasColumnName("Avatar")
             .HasMaxLength(1000)
             .IsUnicode(true);

            //Relation.

            builder.HasMany(t => t.Tags)
               .WithOne()
               .HasForeignKey(t=>t.AppUserId);
            builder.HasMany(t => t.BPFiles)
               .WithOne()
               .HasForeignKey("AppUserId");
            builder.HasMany(t => t.Properties)
              .WithOne()
              .HasForeignKey("AppUserId");
        }
    }
}
